<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" placeholder="请输入1-100之间的整数">
<input type="button" value="猜一猜" id="d" onclick="f()">
<div>
  结果：<span></span>
</div>

<script>
  function f() {
    let s = document.querySelector("span")
    let h = document.querySelector("input");
  let num = parseInt(Math.random()*100)+1;
  for (let j = 0 ; j<10; j++){
    if (h.value == num){
       s.innerText ="恭喜你猜对了"
      console.log(j)
    } else if (h.value>num){
      s.innerText ="猜大了"
      console.log(j)
    } else if (h.value<num){
      s.innerText ="猜小了"
      console.log(j)
    }else if (j=10){
      s.innerText ="你太笨了"
      console.log(j)
    }
  }
  }
</script>
</body>
</html>